package cn.xscrum.vtsp.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.xscrum.common.annotation.Log;
import cn.xscrum.common.enums.BusinessType;
import cn.xscrum.vtsp.domain.VtspMessage;
import cn.xscrum.vtsp.service.IVtspMessageService;
import cn.xscrum.common.core.controller.BaseController;
import cn.xscrum.common.core.domain.AjaxResult;
import cn.xscrum.common.utils.poi.ExcelUtil;
import cn.xscrum.common.core.page.TableDataInfo;

/**
 * 消息持久化记录Controller
 * 
 * @author xscrum
 * @date 2021-10-01
 */
@Controller
@RequestMapping("/vtsp/message")
public class VtspMessageController extends BaseController
{
    private String prefix = "vtsp/message";

    @Autowired
    private IVtspMessageService vtspMessageService;

    @RequiresPermissions("vtsp:message:view")
    @GetMapping()
    public String message()
    {
        return prefix + "/message";
    }

    /**
	 * 查询消息持久化记录列表
     */
    @RequiresPermissions("vtsp:message:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(VtspMessage vtspMessage)
    {
        startPage();
        List<VtspMessage> list = vtspMessageService.selectVtspMessageList(vtspMessage);
        return getDataTable(list);
    }

    /**
	 * 导出消息持久化记录列表
     */
    @RequiresPermissions("vtsp:message:export")
    @Log(title = "消息持久化记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(VtspMessage vtspMessage)
    {
        List<VtspMessage> list = vtspMessageService.selectVtspMessageList(vtspMessage);
        ExcelUtil<VtspMessage> util = new ExcelUtil<VtspMessage>(VtspMessage.class);
        return util.exportExcel(list, "message");
    }

    /**
	 * 新增消息持久化记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
	 * 新增保存消息持久化记录
     */
    @RequiresPermissions("vtsp:message:add")
    @Log(title = "消息持久化记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(VtspMessage vtspMessage)
    {
        return toAjax(vtspMessageService.insertVtspMessage(vtspMessage));
    }

    /**
	 * 修改消息持久化记录
     */
    @GetMapping("/edit/{messageId}")
    public String edit(@PathVariable("messageId") Long messageId, ModelMap mmap)
    {
        VtspMessage vtspMessage = vtspMessageService.selectVtspMessageById(messageId);
        mmap.put("vtspMessage", vtspMessage);
        return prefix + "/edit";
    }

    /**
	 * 修改保存消息持久化记录
     */
    @RequiresPermissions("vtsp:message:edit")
    @Log(title = "消息持久化记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(VtspMessage vtspMessage)
    {
        return toAjax(vtspMessageService.updateVtspMessage(vtspMessage));
    }

    /**
	 * 删除消息持久化记录
     */
    @RequiresPermissions("vtsp:message:remove")
    @Log(title = "消息持久化记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(vtspMessageService.deleteVtspMessageByIds(ids));
    }
}
